import tasks
import redis
from celery.result import ResultSet
from task_config import TASK_CONFIG

redis_client = redis.Redis(
  host=TASK_CONFIG['redis_host'], 
  port=TASK_CONFIG['redis_port'], 
  db=TASK_CONFIG['redis_db'],
  charset="utf-8", 
  decode_responses=True)
redis_client.set('xmlrpc_server', '{}')

files = ['a.txt', 'b.txt']

results = []

for file in files:
  results.append(tasks.execute.delay({
    'file_name': file, 
    'offset': 0, 
    'count': 0, 
    'script_dir': 'scripts', 
    'script_name': 'executor'}))

def on_received_result(task_id, value):
  print('task finished, param: ', value)

ResultSet(results).join(timeout=60*10, callback=on_received_result)